package com.bwie.controller;

import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginInfoVo;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/user/tbUser")
public class TbUserController {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Autowired
    TbUserService tbUserService;

    /**
     * 用户登录
     * @param loginInfoVo
     * @return
     */
    @PostMapping(value = "/userLogin")
    public R userLogin(@RequestBody LoginInfoVo loginInfoVo) {
        return tbUserService.userLogin(loginInfoVo);
    }

    /**
     * 发送验证码
     * @param userMobile
     * @return
     */
    @PostMapping(value = "/sendCode/{userMobile}")
    public R sendCode(@PathVariable("userMobile") String userMobile) {
        return tbUserService.sendCode(userMobile);
    }

    /**
     * 分页查询日志
     * @param pageInfoVo
     * @return
     */
    @PostMapping(value = "/getSysLogByPage")
    public R getSysLogByPage(@RequestBody PageInfoVo pageInfoVo) {
        return tbUserService.getSysLogByPage(pageInfoVo);
    }

    @PostMapping(value = "/testRedis")
    public R testRedis() {
        stringRedisTemplate.opsForValue().set("testkey", "1", 10, TimeUnit.SECONDS);
        return R.OK();
    }

    @PostMapping(value = "/getUserById/{userId}")
    public R getUserById(@PathVariable("userId") Integer userId) {
        return tbUserService.getUserById(userId);
    }
}
